<div class="panel-body">
		<div id="query_area">
			<!-- 查询条件区域begin-->
			<table class="table table-bordered FormView cb-table-fun" border="0"
				cellspacing="1" cellpadding="0">
				
				<tr>
					<td class="cb-label">邮件主题</td>
					<td class="cb-value"><input type="text" id="msubject" name="msubject"
						class="form-control cb-form-control"></td>
					<td class="cb-label">邮件内容</td>
					<td class="cb-value"><input type="text" id="mcontent" name="mcontent"
						class="form-control cb-form-control"></td>
				</tr>
				
				<tr>
					<td class="cb-label">发件人</td>
					<td class="cb-value"><input type="text" id="mshowname" name="mshowname"
						class="form-control cb-form-control"></td>
					<td class="cb-label">收件人</td>
					<td class="cb-value"><input type="text" id="msendname" name="msendname"
						class="form-control cb-form-control"></td>
				</tr>
			</table>
		</div>
		<!-- 查询条件区域end-->
		<!-- 按钮栏布局begin -->
		<div id="toolbar_area" class="toolbar_area">
			<a class="btn btn-default cb-btn" lay-filter="formDemo"
				href="javascript:void(0)" onclick="query()"><i
				class="glyphicon glyphicon-search"></i>&nbsp;查询</a> <a
				lay-filter="hasPermission('mail:tmaildetail:add')" class="btn btn-default cb-btn"
				onclick="send(this)"><i class="glyphicon glyphicon-plus"></i>&nbsp;发送邮件</a><a
				lay-filter="hasPermission('mail:tmaildetail:receive')" class="btn btn-default cb-btn"
				onclick="receive(this)"><i class="glyphicon glyphicon-import"></i>&nbsp;收取</a><a
				lay-filter="hasPermission('mail:tmaildetail:replay')" class="btn btn-default cb-btn"
				onclick="replay(this)"><i class="glyphicon glyphicon-envelope"></i>&nbsp;回复</a><a
				lay-filter="hasPermission('mail:tmaildetail:transmit')" class="btn btn-default cb-btn"
				onclick="transmit(this)"><i class="glyphicon glyphicon-share-alt"></i>&nbsp;转发</a><a
				lay-filter="hasPermission('mail:tmaildetail:remove')" class="btn btn-default cb-btn"
				onclick="remove(this)"><i class="glyphicon glyphicon-trash"></i>&nbsp;删除</a><a
				lay-filter="hasPermission('mail:tmaildetail:read')" class="btn btn-default cb-btn"
				onclick="read(this)"><i class="glyphicon glyphicon-star-empty"></i>&nbsp;已读</a><a
				lay-filter="hasPermission('mail:tmaildetail:readall')" class="btn btn-default cb-btn"
				onclick="readall(this)"><i class="glyphicon glyphicon-star"></i>&nbsp;全部已读</a><a
				lay-filter="hasPermission('mail:tmaildetail:copy')" class="btn btn-default cb-btn"
				onclick="copyTo(this)"><i class="glyphicon glyphicon-floppy-disk"></i>&nbsp;复制到...</a><a
				lay-filter="hasPermission('mail:tmaildetail:move')" class="btn btn-default cb-btn"
				onclick="moveTo(this)"><i class="glyphicon glyphicon-random"></i>&nbsp;移动到...</a>
		</div>
		<!-- 按钮栏布局end -->
		</form>
	</div>
	<table id="jqGrid"></table>
	<div id="jqGridPager"></div>
<script type="text/javascript">
	$(function() {
		$("#jqGrid").jqGrid({
			url : cb.baseurl + 'mail/tmaildetail/query?mtype='+(ptypecode||"")+"&maId="+(pid||"")+"&mfId="+(parentId||""),
			datatype : "json",
			colModel : [ 
				{
					label:'邮件id',
					name : 'mid',
					width : 100,
					key : true,
					hidden:true
				}, 
				{
					label:'发件人',
					name : 'msender',
					width : 100
				},
				{
					label:'主题',
					name : 'msubject',
					width : 100,
					formatter:function(cellvalue, options, rowObject){
						if(rowObject.misRead == "N")
							return "<a href='javascript:showMail(\""+rowObject.mid+"\")'><font font-weight='900' color='red'>"+cellvalue+"</font></a>";
						else if((rowObject.misRead == "Y"))
							return "<a href='javascript:showMail(\""+rowObject.mid+"\")'><font color='blue'>"+cellvalue+"</font></a>";
						else
							return "<a href='javascript:showMail(\""+rowObject.mid+"\")'><font color='blue'>"+cellvalue+"</font></a>";	
					}
				},
				{
					label:'时间',
					name : 'msendTime',
					width : 100
				},
				{
					label:'大小',
					name : 'msize',
					width : 100
				}
			],
			viewrecords : true,
			height : 385,
			rowNum : 10,
			rowList : [ 10, 30, 50 ],
			rownumbers : true,
			rownumWidth : 25,
			autowidth : true,
			multiselect : true,
			pager : "#jqGridPager",
			jsonReader : {
				root : "page.list",
				page : "page.currPage",
				total : "page.totalPage",
				records : "page.totalCount"
			},
			prmNames : {
				page : "page",
				rows : "limit",
				order : "order"
			},
			gridComplete : function() {
				//隐藏grid底部滚动条
				$("#jqGrid").closest(".ui-jqgrid-bdiv").css({
					"overflow-x" : "hidden"
				});
			},
			loadComplete : function(data){
				if((ptypecode||"INBOX")=="INBOX"){
					var orgTree = cb.trees["orgTree"].tree.obj;
					var node = orgTree.getNodeByParam("cbid","INBOX", orgTree.getNodeByParam("cbid",pid, null));
					console.log(node);
					console.log(pid);
					if(data.unread > 0){
						node.name="收件箱("+data.unread+")";
						orgTree.updateNode(node);
					}else if(node && node.name){
						node.name="收件箱";
						orgTree.updateNode(node);
					}
				}
			}
		});

	});

	//查询
	function query() {
		var page = $("#jqGrid").jqGrid('getGridParam', 'page');
		$("#jqGrid").jqGrid('setGridParam', {
			postData : {
		"mid" : $("#mid").val()
		,	
		"maId" : $("#maId").val()
		,	
		"orgId" : $("#orgId").val()
		,	
		"msubject" : $("#msubject").val()
		,	
		"mcontent" : $("#mcontent").val()
		,	
		"msender" : $("#msender").val()
		,	
		"mshowname" : $("#mshowname").val()
		,	
		"msendname" : $("#msendname").val()
		,	
		"msendTime" : $("#msendTime").val()
		,	
		"mtime" : $("#mtime").val()
		,	
		"mtype" : $("#mtype").val()
		,	
		"misRead" : $("#misRead").val()
		,	
		"misStar" : $("#misStar").val()
		,	
		"mstarTime" : $("#mstarTime").val()
		,	
		"createUserId" : $("#createUserId").val()
		,	
		"createTime" : $("#createTime").val()
		,	
		"updateUserId" : $("#updateUserId").val()
		,	
		"updateTime" : $("#updateTime").val()
			
			},
			page : page
		}).trigger("reloadGrid");
	}
	//新增
	function receive(e) {
		$(e).attr("disabled","disabled");
		cb.alert("正在接收邮件，请稍等...");
		$.post(cb.baseurl + "mail/tmaildetail/receiveMail","pid="+(pid||""),function(data){
			$(e).attr("disabled",null);
			query();
			//cb.alert("接收到"+data.count+"封新邮件");
		})
	}
	function showMail(mid){
		var data={};
		data.title="查看邮件";
		data.icon="glyphicon glyphicon-eye-open";
		data.href=cb.baseurl + "mail/tmaildetail/view/"+mid+"?token="+cb.token;
		parent.tab.tabAdd(data);
		setTimeout("query()",1000);
	}
	function send(e){
		var data={};
		data.title="发送邮件";
		data.icon="glyphicon glyphicon-eye-open";
		data.href=cb.baseurl + "mail/tmaildetail/form?token="+cb.token;
		parent.tab.tabAdd(data);
	}
	//修改
	function replay() {
		var id = cb.getselectedrow("#jqGrid");
		if (id){
			var data={};
			data.title="回复邮件";
			data.icon="glyphicon glyphicon-envelope";
			data.href=cb.baseurl + "mail/tmaildetail/replay/"+id+"?token="+cb.token;
			parent.tab.tabAdd(data);
		}
	}
	function read(e) {
		var id = cb.getselectedrows("#jqGrid");
		if (id){
			cb.post("/mail/tmaildetail/read",JSON.stringify(id),function(data){
				query();
			},{contentType:"application/json"})
		}
	}
	function copyTo(e){
		var id = cb.getselectedrows("#jqGrid");
		if (id){
			cb.winopen('修改', '700px', '300px', 'mail/tmaildetail/showcopyormove?ids=' + id+"&type=COPY&pid="+(pid||""),
					'yes', function() {
						query();
					});
		}
	}
	function moveTo(e){
		var id = cb.getselectedrows("#jqGrid");
		if (id){
			cb.winopen('修改', '700px', '300px', 'mail/tmaildetail/showcopyormove?ids=' + id+"&type=MOVE&pid="+(pid||""),
					'yes', function() {
						query();
					});
		}
	}
	function readall(e) {
		$.post(cb.baseurl + "mail/tmaildetail/readall","pid="+(pid||""),function(data){
			query();
		})
	}
	function transmit(e){
		var id = cb.getselectedrow("#jqGrid");
		if (id){
			var data={};
			data.title="转发邮件";
			data.icon="glyphicon glyphicon-share-alt";
			data.href=cb.baseurl + "mail/tmaildetail/transmit/"+id+"?token="+cb.token;
			parent.tab.tabAdd(data);
		}
	}
	function remove(e){
		var ids = cb.getselectedrows("#jqGrid");
		if (ids){
			if(ptypecode == "TRASHBOX"){
				cb.confirm("确定删除吗？",function(){
					cb.post("mail/tmaildetail/remove",JSON.stringify(ids),function(result){
						cb.alert("删除成功",function(){query();});
						
					},{contentType:"application/json"});
					
				})
			}else{
				cb.confirm("确定删除吗？",function(){
					cb.post("mail/tmaildetail/remove2",JSON.stringify(ids),function(result){
						cb.alert("删除成功",function(){query();});
						
					},{contentType:"application/json"});
					
				})				
			}
		}
	}
</script>
</html>